
var mysql = require('mysql');

var pool  = mysql.createPool({
  host            : 'localhost',
  user            : 'root',
  password        : '123456',
  database        : 'cms'
});
 
exports.query = function (sqlStr) {
  return new Promise((resolve, reject) => {
    pool.getConnection((err, connection) => {
      if (err) {
        return reject(err)
      }
      connection.query(sqlStr, (err, ...args) => {
        //操作结束,释放连接
        connection.release()
        if (err) {
          return reject(err)
        }
        resolve(...args)
      })
    })
  })
}



